package cn.minions.config;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.template.Engine;
import com.jfinalplus.plugin.spring.IocKit;
import com.jfinalplus.plugin.spring.SpringDataSourceProvider;
import com.jfinalplus.plugin.spring.SpringPlugin;

import cn.minions.testMybatis.SystemAdmin;
import cn.minions.testSpring.controller.BlogController;

public class MyConfig extends JFinalConfig{

	@Override
	public void configConstant(Constants me) {
		IocKit.processJFinalConfig(this);
		loadPropertyFile("db.properties");
		me.setEncoding("UTF-8");
		me.setDevMode(getPropertyToBoolean("devMode", true));
	}

	@Override
	public void configRoute(Routes me) {
		System.out.println("configRoute");
		me.add("/blog", BlogController.class);
	}

	@Override
	public void configPlugin(Plugins me) {
		SpringPlugin springPlugin = new SpringPlugin("classpath*:spring/applicationContext-*.xml");
		me.add(springPlugin);
		SpringDataSourceProvider prov = new SpringDataSourceProvider(springPlugin);
		// 配置ActiveRecord插件
		ActiveRecordPlugin arp = new ActiveRecordPlugin(prov);
		me.add(arp);
		arp.addMapping("system_admin", SystemAdmin.class);	// 映射blog 表到 Blog模型
		
	}

	@Override
	public void configInterceptor(Interceptors me) {
		System.out.println("configInterceptor");
	}

	@Override
	public void configHandler(Handlers me) {
		System.out.println("configHandler");
	}

	@Override
	public void configEngine(Engine me) {
		System.out.println("configEngine");
	}

}
